package com.sise.wangzhan;

import com.netflix.loadbalancer.ILoadBalancer;
import com.netflix.loadbalancer.IRule;
import com.netflix.loadbalancer.Server;

import java.util.List;

/**
 * @Classname MyRule
 * @Description TODO    自定义负载均衡规则
 * @Date 2020/4/2 9:47
 * @Created by wangzhan
 */
public class MyRule implements IRule {

    ILoadBalancer Ib;

    public MyRule() {
    }

    public MyRule(ILoadBalancer ib) {
        Ib = ib;
    }

    @Override
    public Server choose(Object var1){
        List<Server> servers = Ib.getAllServers();
        System.out.println("这是自定义服务器规则类，输出服务器信息：");
        for (Server server : servers){
            System.out.println("      "+server.getHostPort());
        }
        return servers.get(0);
    }

    @Override
    public void setLoadBalancer(ILoadBalancer var1){
        this.Ib = var1;
    }

    @Override
    public ILoadBalancer getLoadBalancer(){
        return this.Ib;
    }

}
